var t = getApp();

Component({
    properties: {},
    data: {
        show: !1,
        contentList: []
    },
    methods: {
        showPopup: function() {
            this.setData({
                show: !this.data.show
            });
        },
        addAtLast: function() {
            var t = this.data.contentList;
            t.push({
                type: "text",
                value: "",
                visible: !1
            }), this.setData({
                contentList: t
            });
        },
        moveDown: function(t) {
            var e = t.currentTarget.dataset.index, a = this.data.contentList.splice(e, 1);
            this.spliceContent(e + 1, 0, a[0]);
        },
        moveUp: function(t) {
            var e = t.currentTarget.dataset.index, a = this.data.contentList.splice(e, 1);
            this.spliceContent(e - 1, 0, a[0]);
        },
        delOne: function(t) {
            var e = t.currentTarget.dataset.index;
            this.spliceContent(e, 1);
        },
        inserOne: function(t) {
            var e = t.currentTarget.dataset.index;
            this.spliceContent(e + 1, 0, {
                type: "text",
                value: "",
                visible: !1
            });
        },
        changeText: function(t) {
            var e = t.currentTarget.dataset.index, a = t.detail.value;
            this.data.contentList[e].value = a;
        },
        spliceContent: function(t, e, a) {
            void 0 !== a ? this.data.contentList.splice(t, e, a) : this.data.contentList.splice(t, e), 
            this.setData({
                contentList: this.data.contentList
            });
        },
        saveEdit: function() {
            var t = "";
            this.data.contentList.forEach(function(e, a) {
                "text" === e.type && (t += "<p>".concat(e.value, "</p>")), "image" === e.type && (t += '<img src="'.concat(e.value, '"></img>'));
            }), this.showPopup(), this.triggerEvent("saveEdit", t);
        },
        choineImage: function() {
            var t = this;
            wx.chooseImage({
                count: 1,
                sizeType: [ "original", "compressed" ],
                sourceType: [ "album", "camera" ],
                success: function(e) {
                    t.uploadImage(e.tempFilePaths);
                }
            });
        },
        uploadImage: function(e) {
            var a = this, i = t.getNetAddresss("upload.uploadPic");
            wx.showLoading({
                title: "正在上传"
            }), wx.uploadFile({
                url: i,
                filePath: e[0],
                name: "file",
                formData: null,
                success: function(t) {
                    var e = {
                        type: "image",
                        value: JSON.parse(t.data).data.img_url,
                        visible: !1
                    }, i = a.data.contentList;
                    i.push(e), a.setData({
                        contentList: i
                    });
                },
                complete: function(t) {
                    wx.hideLoading();
                }
            });
        }
    }
});